package team.pra.manager.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team.pra.manager.common.ManagerResult;
import team.pra.manager.common.PageHelper;
import team.pra.manager.pojo.Floor;
import team.pra.manager.service.FloorService;

import javax.servlet.http.HttpServletRequest;

/**
 * 楼层的CURD
 */
@RestController
@RequestMapping("/floor")
public class FloorController {
    @Autowired
    private FloorService floorService;
    @GetMapping("/list")
    @RequiresPermissions({"select"})
    public PageHelper listFloor(String token, PageHelper<Floor> pageHelper,
                                @RequestParam(name = "search[value]") String searchvalue,
                                @RequestParam(name = "order[0][column]") Integer orderColunm,
                                @RequestParam(name = "order[0][dir]") String orderDir,
                                HttpServletRequest request){
        String columnName = request.getParameter("columns["+orderColunm+"][data]");
        pageHelper.setColumnName(columnName);
        pageHelper.setSearchValue(searchvalue);
        pageHelper.setOrderDir(orderDir);
        floorService.findFloorByCondition(pageHelper);
        return pageHelper;
    }

    @PostMapping(value = "/insert")
    @RequiresPermissions({"insert"})
    public ManagerResult insertRoomType(String token, Floor floor) {
        return floorService.insertFloorType(floor);
    }
    @PostMapping(value = "/update")
    @RequiresPermissions({"update"})
    public ManagerResult updateRoomType(String token,Floor floor) {
        return floorService.updateFloorType(floor);
    }
    @GetMapping("/delete")
    @RequiresPermissions({"delete"})
    public ManagerResult deleteRoomType(String token,@RequestParam("id")Integer id) {
        return floorService.deleteFloorType(id);
    }
}
